package com.polaris.live.ui.follow

import android.os.Bundle
import androidx.fragment.app.Fragment
import com.blankj.utilcode.util.StringUtils
import com.polaris.live.common.adapter.ViewPagerAdapter
import com.polaris.live.common.ext.setOnSingleClickListener
import com.polaris.live.common.mvvm.base2.BaseVbActivity
import com.polaris.live.common.mvvm.viewmodel.BaseViewModel
import com.polaris.live.databinding.ActivityFollowBinding
import com.polaris.live.translation.R.string
import com.polaris.live.utils.getBooleanOrString
import com.polaris.live.widget.tab.OnTabSelectListener
import com.polaris.live.widget.tab.TabBean

/**
 * FollowActivity
 *
 * @author Created by 半仙 on 2023/9/4/004 14:33
 */
class FollowActivity : BaseVbActivity<BaseViewModel, ActivityFollowBinding>() {

    private val isFans by lazy { intent.getBooleanOrString("isFans", false) }

    private val mFragments = ArrayList<Fragment>(2)

    override fun initView(savedInstanceState: Bundle?) {
        mBinding.icBack.setOnSingleClickListener {
            finish()
        }

        val titles =
            arrayOf(
                StringUtils.getString(string.following),
                StringUtils.getString(string.follower)
            ).map {
                TabBean(it)
            }

        mFragments.add(FollowingFragment())
        mFragments.add(FollowerFragment())

        mBinding.tab.setOnTabSelectListener(object : OnTabSelectListener {
            override fun onTabSelect(position: Int) {
                mBinding.pager.currentItem = position
            }

            override fun onTabReselect(position: Int) {

            }
        })

        val tabAdapter = ViewPagerAdapter(mFragments, this)
        mBinding.pager.adapter = tabAdapter

        mBinding.tab.setViewPage(mBinding.pager)
        mBinding.tab.setTabs(titles)

        if (isFans) {
            mBinding.pager.setCurrentItem(1, false)
        }

    }

}